package com.kunyi.web.service.log.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kunyi.platform.log.entity.dto.SaveOpsDto;
import com.kunyi.platform.mybatis.KyPage;
import com.kunyi.platform.tool.util.KyAssertUtil;
import com.kunyi.web.service.log.core.transform.LogOpsTransform;
import com.kunyi.web.service.log.entity.domain.LogOps;
import com.kunyi.web.service.log.entity.req.LogOpsListReq;
import com.kunyi.web.service.log.entity.resp.LogOpsDetailResp;
import com.kunyi.web.service.log.entity.resp.LogOpsListResp;
import com.kunyi.web.service.log.mapper.LogOpsMapper;
import com.kunyi.web.service.log.service.ILogOpsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName LogOpsServiceImpl
 * @Description log_ops业务实现
 * @Author pengjunjun
 * @Date 2024/3/6 14:30
 * @Version 1.0
 **/
@Service
public class LogOpsServiceImpl extends ServiceImpl<LogOpsMapper, LogOps> implements ILogOpsService {
    @Override
    public Long save(SaveOpsDto saveOps) {
        LogOps logOps = LogOpsTransform.save2Log(saveOps);
        this.save(logOps);
        return logOps.getId();
    }

    @Override
    public PageInfo<LogOpsListResp> pageByParam(LogOpsListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<LogOps> list = baseMapper.listByReq(req);
        return KyPage.page(list,(item) -> LogOpsTransform.log2ListResp(item));
    }

    @Override
    public LogOpsDetailResp detailById(Long id) {
        KyAssertUtil.isTrue(id.longValue() > 0,"参数格式错误");
        LogOps logOps = baseMapper.selectById(id);
        KyAssertUtil.notNull(logOps,"未找到相应日志！");
        return LogOpsTransform.log2DetailResp(logOps);
    }
}
